﻿using Che.AppService.APPRole;
using Che.AppService.AppService.Login;
using Microsoft.AspNetCore.Mvc;
using TR.Domain.Entity.rbac_QXGL;

namespace Che.WebApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class RoleController : Controller
    {
        private readonly APPIRolejue iu;
        private readonly ILogger<LoginController> _logger;
        public RoleController(APPIRolejue iu, ILogger<LoginController> logger)
        {
            this.iu = iu;
            _logger = logger;
        }
        [HttpGet("sb")]
        public Task<List<CeBianlan>> ceBianlans(string jid) {
        
        
           return  iu.CeBianlanSelectAsync (jid);   
    
        }
        [HttpGet("sb2")]
        public Task<rbac_UserRoles> ceBianlans2(int uid)
        {
            return iu.queryU_rolesiD(uid);

        }
        [HttpPost("upload")]
        public async Task<IActionResult> UploadFile( IFormFile file)
        {
            try
            {
                var fileInfo = await iu.UploadAsync(file);
                return Ok(new
                {
                    success = true,
                    message = "文件上传成功",
                    data = new
                    {
                        originalName = fileInfo.OriginalFileName,
                        storedName = fileInfo.StoredFileName,
                        url = Path.Combine(@"D:\chelsea项目\chelseafootball\src\assets", fileInfo.StoredFileName)
                    }
                });
            }
            catch (System.Exception ex)
            {
                return BadRequest(new
                {
                    success = false,
                    message = ex.Message
                });
            }
        }
        [HttpPost("servetable")]
        public void table() {
            iu.serverTable();
        }
    }
}
